package com.bookmanager.www.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bookmanager.www.entity.FlBook;
import com.bookmanager.www.mapper.FlBookMapper;
import com.bookmanager.www.service.FlBookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 图书表 服务实现类
 * </p>
 *
 * @author 风离
 * @since 2021-09-17
 */
@Service
public class FlBookServiceImpl extends ServiceImpl<FlBookMapper, FlBook> implements FlBookService {

    @Resource
    FlBookMapper flBookMapper;

    @Override
    public int insertBookByISBN(String bookId, String bookUpId, int status, String title,
                                String authorIntro, String img, String isbn, String author,
                                String price, String pages, String doubanScore, String douban,
                                String published, int categoriesId, int inventory, String description,
                                String publishing, LocalDateTime createdTimestamp, LocalDateTime updatedTimestamp) {

        int insertBook = flBookMapper.insertBookByISBN(bookId,bookUpId,status,title,authorIntro,
                img,isbn,author,price,pages,doubanScore,douban,published,categoriesId,inventory,description,publishing,
                createdTimestamp,updatedTimestamp);

        return insertBook;
    }

    @Override
    public IPage<FlBook> selectPageExt(FlBook flBook, Integer page, Integer pageSize,Integer cid) {
        try{
            Page<FlBook> p =new Page<>(page,pageSize);
            p.setRecords(flBookMapper.selectPageExt(p,flBook,cid));
            return p;
        }catch (Exception e)
        {
            throw new RuntimeException(e.getMessage());
        }

    }

    @Override
    public IPage<FlBook> selectPageExtZeroBuyBook(FlBook flBook, Integer page, Integer pageSize) {
        try{
            Page<FlBook> p =new Page<>(page,pageSize);
            p.setRecords(flBookMapper.selectPageExtZeroBuyBook(p,flBook));
            return p;
        }catch (Exception e)
        {
            throw new RuntimeException(e.getMessage());
        }
    }
}
